package 蓝桥杯.第十四届蓝桥杯大赛软件赛省赛Java大学B组;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @Title: 买二赠一2
 * @Author 贾金博
 * @Package 蓝桥杯.第十四届蓝桥杯大赛软件赛省赛Java大学B组
 * @Date 2024/4/11 21:38
 * @description:
 */
public class 买二赠一2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n + 10];
        boolean[] st = new boolean[n + 10]; // 表示这个数 有没有是被赠送的
        for(int i = 1; i <= n; ++ i ) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a, 1, n + 1);

        long ret = 0;
        for(int i = n, j = n; i >= 1; -- i ) {
            while(st[i] && i >= 1) {
                i -- ;
            }
            if(i <= 0 ) {
                break;
            }
            int t1 = a[i];
            ret += t1;
            i -- ;
            if(i <= 0 )break;

            while(st[i] && i >= 1 ) {
                i--;
            }
            if(i <= 0) {
                break;
            }
            int t2 = a[i];
            ret += t2;

            int find = (Math.min(t1, t2)) / 2;
           // System.out.println("t1 = " + t1 + " t2 = " + t2 + " find = " + find);
            for(; j >= 1; -- j ) {
                if(!st[j] && a[j] <= find) {
                   // System.out.println("a[j] = " + a[j]);
                    st[j] = true;
                    break;
                }
            }

        }
        System.out.println(ret);
    }
}
